package jj.fly.activiti.leavebill.service.impl;

import jj.fly.activiti.leavebill.dao.mybatis.LeaveBillMapper;
import jj.fly.activiti.leavebill.dao.mybatis.custom.LeaveBillMapperCustom;
import jj.fly.activiti.leavebill.domain.LeaveBill;
import jj.fly.activiti.leavebill.domain.LeaveBillExample;
import jj.fly.activiti.leavebill.domain.custom.LeaveBillCustom;
import jj.fly.activiti.leavebill.service.ILeaveBillService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Author: jiangjun
 * Date: 2018/5/9
 * Time: 下午2:18
 * Description:
 */
@Service("leaveBillService")
public class LeaveBillServiceImpl implements ILeaveBillService {

    @Autowired
    private LeaveBillMapper mapper;

    @Autowired
    private LeaveBillMapperCustom mapperCustom;

    @Override
    public List<LeaveBillCustom> getDataList(Integer employeeId) {
//        LeaveBillExample example = new LeaveBillExample();
//        example.or().andEmployeeIdEqualTo(employeeId);
//        List<LeaveBill> list = mapper.selectByExample(example);
        List<LeaveBillCustom> list = mapperCustom.getDataList(employeeId);
        return list;
    }

    @Override
    public LeaveBill getDataById(Integer id) {
        return mapper.selectByPrimaryKey(id);
    }

    @Override
    public void save(LeaveBill leaveBill) {
        if(leaveBill.getId() == null){
            // insert
            mapper.insertSelective(leaveBill);
        }else{
            // update
            mapper.updateByPrimaryKeySelective(leaveBill);
        }
    }

    @Override
    public void deleteById(Integer id) {
        mapper.deleteByPrimaryKey(id);
    }
}
